package com.sky.controller.admin;

import com.sky.exception.BaseException;
import com.sky.result.Result;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("admin/shop")
public class ShopController {


    @Autowired
    private RedisTemplate redisTemplate;

    String sky = "sky:admin:shop";

    @GetMapping("status")
    public Result status() {
        if (redisTemplate.hasKey(sky)) {
            Object o = redisTemplate.opsForValue().get(sky);
            Integer status = Integer.valueOf(o + "");
            return Result.success(status);
        }
        throw new BaseException("请先设置状态");
    }

    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status) {
        try {
            redisTemplate.opsForValue().set(sky, status);
        } catch (Exception e) {
            throw new BaseException("redis设置异常");
        }
        return Result.success();
    }


}
